//		Written by Carl Lindberg Copyright (c) 1994 by Carl Lindberg.
//				Version 1.0.  All rights reserved.
//
//		This notice may not be removed from this source code.
//
//	This program is included in the MiscKit by permission from the author
//	and its use is governed by the MiscKit license, found in the file
//	"LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
//	for a list of all applicable permissions and restrictions.
//	

#import <appkit/appkit.h>
#import "mscarl.h"


#define NUMSTRINGS 1
#define NUMSEARCHES 5

char *strs[NUMSTRINGS] = {
"abcABCaBC456 HelloabcdHiabc",
};

char *srchs[NUMSEARCHES] = {
"abc",
"ABC",
"abcabc",
NULL,
"c45"
};

void main()
{
  int i,j,k,l,m;
  id str = [MiscString new];
  id tmp;

  for (i=0;i<NUMSTRINGS;i++) {
    printf("----------------------------------------------\n");
    [str setStringValue:strs[i]];
    printf("String now is: <%s>\n",strs[i]);
    for (j=0;j<NUMSEARCHES;j++) {
      printf("Num of '%s': %d  nocase: %d  nocase/overlap: %d\n",srchs[j],
        [str numOf:srchs[j]],
        [str numOf:srchs[j] caseSensitive:NO],
        [str numOf:srchs[j] caseSensitive:NO overlap:YES]);
        printf("Spots of '%s' nocase/overlap:",srchs[j]);
        for (k=0;(l = [str spotOfStr:srchs[j] occurrenceNum:k caseSensitive:NO overlap:YES]) >=0;k++) printf(" %d",l);
        printf("\nrSpots of '%s' nocase/overlap:",srchs[j]);
        for (k=0;(l = [str rspotOfStr:srchs[j] occurrenceNum:k caseSensitive:NO overlap:YES]) >=0;k++) printf(" %d",l);
        printf("\n");
        for (k=-1;k<5;k++) printf("replace %dth '%s' with '[]': '%s'\n",
          k,srchs[j],[[[str copy] replace:srchs[j] with:"[]" occurrenceNum:k caseSensitive:NO] stringValueAndFree]);
        for (k=-1;k<5;k++) printf("overlap replace %dth '%s' with '[]': '%s'\n",
          k,srchs[j],[[[str copy] replace:srchs[j] with:"[]" occurrenceNum:k caseSensitive:NO overlap:YES] stringValueAndFree]);
        [(tmp = [str copy]) replaceEveryOccurrenceOf:srchs[j] with:"[]"];
 	printf("replace all '%s' with '[]': %s\n",srchs[j],
	  [tmp stringValueAndFree]);
        [(tmp = [str copy]) replaceEveryOccurrenceOf:srchs[j] with:"[]" caseSensitive:NO];
 	printf("nocase replace all '%s' with '[]': %s\n",srchs[j],
	  [tmp stringValueAndFree]);
        [(tmp = [str copy]) replaceEveryOccurrenceOf:srchs[j] with:"[]" caseSensitive:NO overlap:YES];
 	printf("nocase/overlap replace all '%s' with '[]': %s\n",srchs[j],
	  [tmp stringValueAndFree]);
     }
   }
  [str free];
}      


